﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL;
using Gift.Model;


namespace WebSite.cn.service
{
    public partial class festival : BasePage
    {
        DALNews theNews = new DALNews();
        DALGoods theGoods = new DALGoods();
        StringBuilder _sbLeftBody01 = new StringBuilder();

        public StringBuilder SbLeftBody01
        {
            get { return _sbLeftBody01; }
        }
        StringBuilder _sbLeftBody02 = new StringBuilder();

        public StringBuilder SbLeftBody02
        {
            get { return _sbLeftBody02; }
        }

        StringBuilder _sbLeftBody03 = new StringBuilder();

        public StringBuilder SbLeftBody03
        {
            get { return _sbLeftBody03; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.GetArticleList();
        }


        public string WriterGoodsHtml()
        {
            StringBuilder sGoodsHtml = new StringBuilder();

            DataTable dtGoods = theGoods.GetList(" isnull(visible,0)=1 and isnull(isSale,0)=1 and termsId in(select id from tbTerms where termsName like '%中秋节%')  order by goodsOrder ").Tables[0];

            int iRowIndex = 0;
            for (int i = 0; i < dtGoods.Rows.Count; i++)
            {
                if (i % 3 == 0 )
                {
                    sGoodsHtml.Append("<tr>");
                  
                }
                sGoodsHtml.AppendFormat("  <td class=\"card_pic\"><img src=\"/uploadfile/product/{0}\"  "
                                         + " onmouseover=\"this.className='htmer_img'\" onmouseout=\"this.className=\'htmer_img_none'\" /> </td> "
                                        + " <td  class=\"card_inst\"><p class=\"list_card_title\">{1}</p><p><em>兑换价：{2}福点</em></p> "
                                        + " <p><a href=\"{3}\" target=\"_self\" ><img src=\"/cn/serviceImages/submit.gif\" class=\"img_submit\" alt=\"\" /></a> </p> "
                                        + " </td> "
                                        , dtGoods.Rows[i]["smallPic"].ToString()
                                        , dtGoods.Rows[i]["goodsName"].ToString()
                                        , dtGoods.Rows[i]["changePoints"].ToString()
                                        , "/cn/goodsDetail.html?gid=" + dtGoods.Rows[i]["goodsId"].ToString()
                                        );
                iRowIndex++;
                if (iRowIndex % 3 == 0 )
                {
                    sGoodsHtml.Append("</tr>");
                }
            }
            if (dtGoods != null)
            {
               if( dtGoods.Rows.Count % 3 == 1)
                {
                     sGoodsHtml.Append("<td column='4'></td></tr>");
                }
               else if (dtGoods.Rows.Count % 3 == 2)
               {
                   sGoodsHtml.Append("<td column='2'></td></tr>");
               }
            }
            return sGoodsHtml.ToString();

        }


        void GetArticleList()
        {
            //节日慰问

            DataTable table = theNews.GetList(1, "typeid in(select typeId from tbNewsType where typeName='中秋节') and visible=1 and isnew=1", "updatetime desc").Tables[0];
            if (table != null && table.Rows.Count > 0)
            {

                _sbLeftBody01.Append(table.Rows[0]["newsContent"].ToString());


                //int iRowIndex = 0;
                //foreach (DataRow row in table.Rows)
                //{
                //    if (iRowIndex < 5)
                //    {
                //        _sbLeftBody01.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span> </li>"
                //                               , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                //                               , row["newsname"].ToString()
                //                               , fun.Left(row["newsname"].ToString(), 20) + ".."
                //                               );
                //    }
                //    else if (iRowIndex >= 5 && iRowIndex < 10)
                //    {
                //        _sbLeftBody02.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span> </li>"
                //                                , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                //                                , row["newsname"].ToString()
                //                                , fun.Left(row["newsname"].ToString(), 20) + ".."
                //                                );
                //    }
                //    else
                //    {
                //        _sbLeftBody03.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span></li>"
                //                               , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                //                               , row["newsname"].ToString()
                //                               , fun.Left(row["newsname"].ToString(), 20) + ".."
                //                               );
                //    }
                //    iRowIndex++;
             //   }
            }


        }
    }
}